﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WpfCourse.Common;
using WpfCourse.Model;

namespace WpfCourse.ViewModel
{
    public class LoginViewModel
    {
        public CommandBase CloseWindowCommand { get; set; }
        public CommandBase LoginCommand { get; set; }

        public LoginModel LoginModel { get; set; }


        public LoginViewModel()
        {
            // 关闭窗口的命令
            this.CloseWindowCommand = new CommandBase();
            this.CloseWindowCommand.DoCanExecute = new Func<object, bool>(o => true);
            this.CloseWindowCommand.DoExecute = new Action<object>(o => {
                (o as Window).Close();
            });

            // LoginModel
            this.LoginModel = new LoginModel();

            // 登录命令
            this.LoginCommand = new CommandBase();
            this.LoginCommand.DoCanExecute = new Func<object, bool>(o => true);
            this.LoginCommand.DoExecute = new Action<object>(o =>
            {
                if (LoginModel.Login())
                {
                    (o as Window).DialogResult = true;
                }
            });
        }
    }
}
